import type { Component } from 'vue/dist/vue'
import type { ISchema } from '@formily/vue'
import type { Form } from '@formily/core'
import { FormProvider, createSchemaField } from '@formily/vue'

interface IParams {
  schema: ISchema
  components?: Record<string, Component>
  form: Form
  scope?: Record<string, any>
}

export default function ({ schema, form, components, scope }: IParams) {
  const { SchemaField } = createSchemaField({ components: { ...components } })
  const SchemaForm = () => <FormProvider form={form}><SchemaField schema={schema} scope={{ ...scope }} /></FormProvider>
  return {
    SchemaForm,
  }
}
